#ifndef _MEMRW_H
#define _MEMRW_H 1

typedef unsigned char BYTE;
typedef unsigned int  WORD;
typedef unsigned long DWORD;
typedef unsigned char BOOL;


typedef struct MemBox  * MemBoxPtr;
struct MemBox{
	    struct MemBox * ptr;
	    BYTE * allocPtr;	
};

/*
data link 

                NULL
				  ^
                  |
                  | 
                ---------------      
               |     | BYTE * |------>NULL          
                --------------- 
				  ^
                  |
                  |                   
                ---------------      
               |     | BYTE * |------>memory block               
                --------------- 
				  ^
                  |
                  | 
                ---------------      
               |     | BYTE * |------>memory block               
                --------------- 
				  ^
                  |
                  | 
                ---------------      
    startPtr-->|     | BYTE * |------>memory block          
                --------------- 

*/
void insertMemBox(BYTE * ptr);
//before program exit, call this function.
void freeMemBox();

BYTE *alignMem(BYTE * ptr, int alignNum);
/******************************************************************************
    Function:
        allocAlignMem

    Description:
	 allocate a aligned memory block, also insert the memory address in memory box.
	 If you want a 1k memory size, and aligned 512 boundary, you must give size no less than
	 1k + 512 -1.
	 Invoker calcultate the memory size.

    Entry:
        int size
        int alignNum

    Exit:
        pointer which pointer to aligned address.
******************************************************************************/
BYTE *  allocAlignMemInBox(int size,   int alignNum);


/******************************************************************************
    Function:
        allocAlignMem

    Description:
	 allocate a aligned memory block.
	 If you want a 1k memory size, and aligned 512 boundary, you must give size no less than
	 1k + 512 -1.
	 Invoker calcultate the memory size.

    Entry:
        int size
        int alignNum

    Exit:
        pointer which pointer to aligned address.
******************************************************************************/
BYTE *  allocAlignMem(int size,   int alignNum);
DWORD calcLineAddress(BYTE * Ptr);
void  memCopy(void * dest, const void * src ,  int n);
void cleanBuffer(BYTE * bufferPtr , int size);
void  dump(BYTE * StartPtr, int n);
void  dumpDWORD(DWORD * StartPtr, int n);
 
#endif